package org.zjt.mock.demo.mock.config;

import lombok.extern.slf4j.Slf4j;
import org.springframework.format.Formatter;

import java.text.ParseException;
import java.time.LocalDateTime;
import java.time.format.DateTimeFormatter;
import java.util.Date;
import java.util.Locale;

/**
 * Description:
 *
 * @author juntao.zhang
 * Date: 2018-06-21 下午6:31
 * @see
 */
@Slf4j
public class LocalDateTimeFormatter implements Formatter<LocalDateTime> {

    private static final DateTimeFormatter DATE_TIME_FORMATTER =  DateTimeFormatter.ofPattern("yyyy-MM-dd HH:mm:ss");

    @Override
    public LocalDateTime parse(String text, Locale locale) throws ParseException {
        log.info("---------------------");
        LocalDateTime localDateTime = LocalDateTime.parse(text, DATE_TIME_FORMATTER);
        return localDateTime;
    }

    @Override
    public String print(LocalDateTime object, Locale locale) {
        String format = object.format(DATE_TIME_FORMATTER);
        return format;
    }
}
